package bai5.model;

import java.text.ParseException;
import java.util.Calendar;
import java.util.Scanner;

import bai5.service.EmployeeAPI;
import bai5.service.implement.EmployeeDAO;

public class Employee {
	private String ten;
	private String date;
	private String dc;
	private String gt;
	private String startDate;
	private int cv;
	private int luong;
	private int tienluong;
	private String stt;
	public Employee(){
	}
	public Employee(String ten, String date, String dc, String gt,
			String startDate, int cv,int luong) {
		super();
		this.ten = ten;
		this.date = date;
		this.dc = dc;
		this.gt = gt;
		this.startDate = startDate;
		this.cv = cv;
		this.luong=luong;
	}
	EmployeeAPI app=new EmployeeDAO();
	public String getTen() {
		return ten;
	}
	public void setTen(String ten) {
		this.ten = ten;
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public String getDc() {
		return dc;
	}

	public void setDc(String dc) {
		this.dc = dc;
	}

	public String getGt() {
		return gt;
	}

	public void setGt(String gt) {
		this.gt = gt;
	}
	public String getStartDate() {
		return startDate;
	}
	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}
	public int getCv() {
		return cv;
	}
	public void setCv(int cv) {
		this.cv = cv;
	}
	public int getLuong() {
		return luong;
	}
	public void setLuong(int luong) {
		this.luong = luong;
	}
	public Employee inputEmployee() {
		Scanner ip=new Scanner(System.in);
		System.out.println("==============Them moi nhan vien=================");
		System.out.println("Nhap vao ten: ");
		String ten=ip.nextLine();
		while(ten.trim().equalsIgnoreCase("")){
			System.out.println("Chua nhap ten");
			ten=ip.nextLine();
		}
		System.out.println("Nhap ngay thang nam sinh(dd/mm/yyyy");
		String date=ip.nextLine();
		while(date.trim().equalsIgnoreCase("")){
			System.out.println("Chua nhap ngay thang nam sinh");
			date=ip.nextLine();
			Calendar.getAvailableCalendarTypes();
		}
		if(!app.isValiDate(date)){
			System.out.println("Nhap khong dung dinh dang! vui long nhap lai");
			date=ip.nextLine();
		}
		System.out.println("Nhap vao dia chi");
		String dc=ip.nextLine();
		while(dc.trim().equalsIgnoreCase("")){
			System.out.println("Chua nhap dia chi");
			dc=ip.nextLine();
		}
		System.out.println("Nhap vao gioi tinh");
		String gt=ip.nextLine();
		while(gt.trim().equalsIgnoreCase("")){
			System.out.println("chua nhap gioi tinh");
			gt=ip.nextLine();
		}
		System.out.println("Nhap vao ngay bat dau lam viec");
		String startDate=ip.nextLine();
		while(startDate.trim().equalsIgnoreCase("")){
			System.out.println("Chua nhap ngay bat dau lam viec");
			startDate=ip.nextLine();
		}
		if(!app.isValiDate(startDate)){
			System.out.println("Nhap khong dung dinh dang.Vui long nhap lai!");
			startDate=ip.nextLine();
		}
		System.out.println("Nhap chuc vu");
		System.out.println("1.Truong nhom");
		System.out.println("2.Truong du an");
		System.out.println("3.Nhan vien");
		int cv=ip.nextInt();
		System.out.println("Nhap luong:");
		int luong=ip.nextInt();
		Employee emp=new Employee(ten,date,dc,gt,startDate, cv,luong);
		return emp;
	}
	public void display(Employee emp) throws ParseException {
		String stt="|01";
		int tienluong=emp.luong+app.pcThamnien(app.thamNien(emp.startDate))+app.pcChucvu(emp.cv);
		String tl=app.formatNumber(tienluong);
		System.out.println("----------------------------------------------------------------------------------------------------");
		System.out.println("|Stt\t|Ho va ten\t|Chuc vu\t|Ngay thang nam sinh\t|Ngay lam viec\t|Tuoi\t|Tien luong");
		System.out.println("----------------------------------------------------------------------------------------------------");
		System.out.println(stt+" \t|"+emp.ten + " \t\t|" + app.loaiCV(emp.cv) + " \t|" + emp.date + " \t\t|" +emp.startDate+" \t|"+app.tuoi(emp.date)+" \t|" +tl);
		System.out.println("----------------------------------------------------------------------------------------------------");
	}
}
